//
//  LKMyShopListCell.m
//  Mideleague_Agent
//
//  Created by Zhiwang on 2020/5/25.
//  Copyright © 2020 Zhiwang. All rights reserved.
//

#import "LKMyShopListCell.h"


@interface LKMyShopListCell()

@property (weak, nonatomic) IBOutlet UILabel *shopNameLabel;
@property (weak, nonatomic) IBOutlet UILabel *shopAccountLabel;
@property (weak, nonatomic) IBOutlet UILabel *tradeMoneyLabel;
@property (weak, nonatomic) IBOutlet UILabel *openDateLabel;
@property (weak, nonatomic) IBOutlet UIImageView *iconImageView;


@end



@implementation LKMyShopListCell

- (void)awakeFromNib {
    [super awakeFromNib];
    self.leftBtn.layer.cornerRadius = 12;
    self.leftBtn.layer.borderWidth = 1;
    self.leftBtn.layer.borderColor = yellowDefaultColor.CGColor;
    self.leftBtn.layer.masksToBounds = YES;
    self.rightBtn.layer.cornerRadius = 12;
    self.rightBtn.layer.masksToBounds = YES;
    self.rightBtn.layer.borderWidth = 1;
    self.rightBtn.layer.borderColor = yellowDefaultColor.CGColor;
    // Initialization code
}
-(void)setListType:(CellListType)listType{
    _listType = listType;
    switch (listType) {
        case CellListTypeMyShop:
        {

        }
            break;
        case CellListTypeMySuboradinate:
        {
//            [self.rightBtn removeFromSuperview];
            self.leftBtnWidth.constant = 82;
        }
            break;
        default:
            break;
    }
}
-(void)setMyShoplistModel:(LKMyShoplistModel *)myShoplistModel{
    _myShoplistModel = myShoplistModel;
    [self.iconImageView sd_setImageWithURL:[NSURL URLWithString:_myShoplistModel.logo_url] placeholderImage:[UIImage imageNamed:@"shoPlaceholder"]];
    NSString *dateStr = [NSString timestampSwitchTime:[_myShoplistModel.add_time integerValue] andFormatter:@"YYYY-MM-dd"];
    self.openDateLabel.text = [NSString stringWithFormat:@"开户时间:%@",dateStr];
    self.shopNameLabel.text = _myShoplistModel.merchant_name;
    self.shopAccountLabel.text = [NSString stringWithFormat:@"商户账号:%@",_myShoplistModel.merchant_phone];
    self.tradeMoneyLabel.text = [NSString stringWithFormat:@"交易总额:%@",_myShoplistModel.total_amout];
    if (_myShoplistModel.agency_business.length == 0) {
        self.leftBtn.hidden = YES;
        self.rightBtn.hidden = YES;
    }else if([_myShoplistModel.agency_business containsString:@"3"]){
        self.leftBtn.hidden = NO;
        self.rightBtn.hidden = NO;
    }else if ([_myShoplistModel.agency_business containsString:@"1"] && ![_myShoplistModel.agency_business containsString:@"3"]){
        self.leftBtn.hidden = NO;
        self.rightBtn.hidden = YES;
    }
}
-(void)setMySuboralistModel:(LKMySuboraListModel *)mySuboralistModel{
    _mySuboralistModel = mySuboralistModel;
    [self.iconImageView sd_setImageWithURL:[NSURL URLWithString:_mySuboralistModel.logo_url] placeholderImage:[UIImage imageNamed:@"shoPlaceholder"]];
    NSString *dateStr = [NSString timestampSwitchTime:[_mySuboralistModel.add_time integerValue] andFormatter:@"YYYY-MM-dd"];
    self.openDateLabel.text = [NSString stringWithFormat:@"加入时间:%@",dateStr];
    self.shopNameLabel.text = _mySuboralistModel.agent_name;
    self.shopAccountLabel.text = [NSString stringWithFormat:@"手机号:%@",_mySuboralistModel.user_phone];
    self.tradeMoneyLabel.text = [NSString stringWithFormat:@"交易总额:%@",_mySuboralistModel.total_amount];
    [self.leftBtn setTitle:_mySuboralistModel.type_name forState:UIControlStateNormal];
    NSString *identi = [_mySuboralistModel.identi isEqualToString:@"1"] ? @"内部":@"外部";
    [self.rightBtn setTitle:identi forState:UIControlStateNormal];
}
- (void)setSelected:(BOOL)selected animated:(BOOL)animated {
    [super setSelected:selected animated:animated];
    self.multipleSelectionBackgroundView = [UIView new];
    self.tintColor = [UIColor redColor];
    // Configure the view for the selected state
}
-(void)layoutSubviews
{
    for (UIControl *control in self.subviews){
        if ([control isMemberOfClass:NSClassFromString(@"UITableViewCellEditControl")]){
            for (UIView *v in control.subviews)
            {
                if ([v isKindOfClass: [UIImageView class]]) {
                    UIImageView *img=(UIImageView *)v;
                    if (self.selected) {
                        img.image=[UIImage imageNamed:@"xuanzhong_customer"];
                        self.myShoplistModel.selected = YES;
                    }else
                    {
                        img.image=[UIImage imageNamed:@"weixuanzhong_customer"];
                        self.myShoplistModel.selected = NO;
                    }
                }
            }
        }
    }
    [super layoutSubviews];
}
- (void)setEditing:(BOOL)editing animated:(BOOL)animated
{
    [super setEditing:editing animated:animated];
    for (UIControl *control in self.subviews){
        if ([control isMemberOfClass:NSClassFromString(@"UITableViewCellEditControl")]){
            for (UIView *v in control.subviews)
            {
                if ([v isKindOfClass: [UIImageView class]]) {
                    UIImageView *img=(UIImageView *)v;
                    if (!self.selected) {
                        img.image=[UIImage imageNamed:@"weixuanzhong_customer"];
                    }else{
                        img.image=[UIImage imageNamed:@"xuanzhong_customer"];
                    }
                }
            }
        }
    }

}
@end
